package com.hs.biye.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hs.biye.constant.MessageConstant;
import com.hs.biye.excepction.BaseException;
import com.hs.biye.model.DTO.RegistrationRequest;
import com.hs.biye.model.VO.PatientVo;
import com.hs.biye.model.VO.RegistrationVo;
import com.hs.biye.model.entity.Patient;
import com.hs.biye.model.entity.Registration;
import com.hs.biye.model.reslut.ResultPage;
import com.hs.biye.service.RegistrationService;
import com.hs.biye.mapper.RegistrationMapper;
import org.aspectj.bridge.Message;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
* @author haoshuai
* @description 针对表【registration】的数据库操作Service实现
* @createDate 2024-01-18 14:05:00
*/
@Service
public class RegistrationServiceImpl extends ServiceImpl<RegistrationMapper, Registration>
    implements RegistrationService{

    @Resource
    private RegistrationMapper registrationMapper;

    @Override
    public ResultPage<RegistrationVo> getPage(RegistrationRequest requestDate) {
        Integer page = requestDate.getPages();
        Integer size = requestDate.getSize();

        IPage<RegistrationVo> page2 = new Page<>(page, size);
        registrationMapper.selectMyPage(page2,requestDate);

        List<RegistrationVo> records = page2.getRecords();
        Long total = page2.getTotal();
        Long current = page2.getCurrent();
        Long pages = page2.getPages();
        records.forEach(item->{
           if (item.getIsDeal().equals("0")){
               item.setIsDeal("否");
           }else {
               item.setIsDeal("是");
           }
           if (item.getGender().equals("0")){
               item.setGender("女");
           }else {
               item.setGender("男");
           }
        });
        return ResultPage.success(records, total,current,pages);
    }


    //删除
    public Boolean deleteRegistration(Integer id){
        if (id == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        return removeById(id);
    }


    //获取挂号记录
    @Override
    public List<RegistrationVo> regList(Integer id) {
        if (id == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        List<RegistrationVo> res = baseMapper.selectListMy(id);
        return res;
    }

    @Override
    public Boolean addRegistration(Registration registration) {
        if (registration == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        boolean save = save(registration);
        return save;
    }
}




